import { 
  OPEN_MESSAGE_DIALOG,
  CLOSE_MESSAGE_DIALOG,
} from '../constants';

const initialState = {
  // 开启聊天会话框
  openMessageDialog: false,
  // 对于一个chatroom
  friendId: null,
  friendName: null,
  friendImg: null,
  chatroomId: null,
};

export default function(state = initialState, action) {
  switch (action.type) {
    case OPEN_MESSAGE_DIALOG:
      return Object.assign({}, state, {
        openMessageDialog: true,
        friendId: action.payload.friendId,
        friendName: action.payload.friendName,
        friendImg: action.payload.friendImg,
        chatroomId: action.payload.chatroomId,
      });
    case CLOSE_MESSAGE_DIALOG:
      return Object.assign({}, state, {
        openMessageDialog: false,
        friendId: null,
        friendName: null,
        friendImg: null,
        chatroomId: null,
      });
    default:
      return state
  }
};
